package com.gtq.uhome.controller;

import com.gtq.uhome.result.Result;
import com.gtq.uhome.service.BasicSettingsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping(value = "/basicSettings")
@ResponseBody
@CrossOrigin
@Api(tags = "总站点基础设置接口说明文档 咨询：李龙")
public class BasicSettings {
    @Resource
    BasicSettingsService basicSettingsService;

    /**
     * 总站台 基础设置中客服电话和用户
     *
     * @return 返回true：表示保存成功 false：表示保存失败
     */
    @PostMapping(value = "/setTime")
    @ApiOperation(value = "设置派单人员接单时间", notes = "以setTime字段传输值", response = Boolean.class, httpMethod = "POST")
    @ApiImplicitParam(name = "setTime", value = "派单人员接单时间", defaultValue = "null", dataType = "String", required = true, paramType = "query")
    public Result setDispatchTime(@RequestBody Map setTime1) {
        String setTime = (String) setTime1.get("setTime");
        //打印接收数据
        System.out.println("设置派单人员接单时间：" + setTime);
        Boolean aBoolean = basicSettingsService.setDispatchTime(setTime);
        if (aBoolean) {
            return Result.ok(null, "保存成功");
        }
        else {
            return Result.failed("保存失败");
        }

    }

    /**
     * 总站台 基础设置中客服电话和用户
     *
     * @return 返回true：表示保存成功 false：表示保存失败
     */
    @PostMapping
    @ApiOperation(value = "保存客服电话和用协议的方法,发送数据的字段为phoneNumber(客服电话)，userAgreement（用户协议）", notes = "basicSettings", response = Boolean.class, httpMethod = "POST")
    @ApiImplicitParams({@ApiImplicitParam(name = "phoneNumber", value = "客服电话", defaultValue = "null", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "userAgreement", value = "用户协议说明", defaultValue = "null", dataType = "String", required = true, paramType = "query")})
    public Result basicSettings(@RequestBody Map map) {
        String phoneNumber = (String) map.get("phoneNumber");
        String  userAgreement = (String) map.get("userAgreement");
        //打印接收数据
        System.out.println("客服电话：" + phoneNumber);
        System.out.println("用户协议说明：" + userAgreement);
        Boolean aBoolean = basicSettingsService.basicSettings(phoneNumber, userAgreement);
        if (aBoolean) {
            return Result.ok(null, "保存成功");
        }
        else {
            return Result.failed("保存失败");
        }
    }
}
